import { PageContainer } from '@ant-design/pro-layout';
import {Card, Alert, Typography, message, Row, Col, Statistic, Button, Tag, Divider} from 'antd';
import {useIntl, FormattedMessage, history} from 'umi';
import styles from './Welcome.less';
import React, {useEffect, useRef, useState} from "react";
import request from "@/utils/request";
import ProTable from "@ant-design/pro-table";
import {PlusOutlined} from "@ant-design/icons";

export default () => {
  const actionRef = useRef();
  const [data, dataUpdate] = useState({})
  useEffect(() => {
    request(`/api/index/getTotal`).then(res => {
      if (res.Code != 0) {
        message.error(res.Msg)
      }
      console.log(res)
      if (res.Data) {
        console.log(res.Data)
        dataUpdate(res.Data)
      }
    })
  }, [])
  const columns = [
    {
      title: '矿工号',
      dataIndex: 'MinerId',
      sorter: (a, b) => a.MinerId > b.MinerId,
    },
    {
      title: '矿池名称',
      dataIndex: 'PoolName',
      sorter: (a, b) => a.PoolName > b.PoolName,
    },
    {
      title: '扇区大小',
      dataIndex: 'Size',
      sorter: (a, b) => a.Size > b.Size,
    },
    {
      title: '矿工余额(Fil)',
      dataIndex: 'Balance',
      sorter: (a, b) => a.Balance - b.Balance,
      render: (text) => {
        return text.toFixed(2)
      }
    },
    {
      title: '有效算力(TiB)',
      dataIndex: 'Power',
      sorter: (a, b) => a.Power - b.Power,
      render: (text) => {
        return text.toFixed(2)
      }
    },
    {
      title: '算力占比(%)',
      dataIndex: 'PowerRatio',
      sorter: (a, b) => a.PowerRatio - b.PowerRatio,
      render: (text) => {
        return text.toFixed(4)
      }
    },
    {
      title: '累计出块数',
      dataIndex: 'RewardCount',
      sorter: (a, b) => a.RewardCount - b.RewardCount,
    },
    {
      title: '累计出块奖励(Fil)',
      dataIndex: 'RewardFil',
      sorter: (a, b) => a.RewardFil - b.RewardFil,
      render: (text) => {
        return text.toFixed(2)
      }
    },
    {
      title: '错误扇区数',
      dataIndex: 'FaultySectors',
      sorter: (a, b) => a.FaultySectors - b.FaultySectors,
    },
    {
      title: '今天密封算力',
      dataIndex: 'TodayPowerGrowth',
      sorter: (a, b) => a.TodayPowerGrowth - b.TodayPowerGrowth,
      render: (text) => {
        return text.toFixed(2)
      }
    },

    {
      title: '今天预估密封算力',
      dataIndex: 'ExpectIncreaseComputingPower',
      sorter: (a, b) => a.ExpectIncreaseComputingPower - b.ExpectIncreaseComputingPower,
      render: (text) => {
        return text.toFixed(2)
      }
    },
    {
      title: '今天幸运值',
      dataIndex: 'TodayLucky',
      sorter: (a, b) => a.TodayLucky - b.TodayLucky,
      render: (text) => {
        return text.toFixed(2)
      }
    },
    {
      title: '今天出块异常',
      dataIndex: 'TodayAbnormalBlock',
      sorter: (a, b) => a.TodayAbnormalBlock - b.TodayAbnormalBlock,
      render: (text,record) => {
        if (!record.DoneRoundWinner ) {
          return "-"
        }
        return text
      },
    },
    {
      title: '今天罚币',
      dataIndex: 'TodayBurnFil',
      sorter: (a, b) => a.TodayBurnFil - b.TodayBurnFil,
      render: (text) => {
        return text.toFixed(2)
      }
    },
  ];
  return (
    <PageContainer>
      <Row gutter={24}>
        <Col
          xl={24}
          lg={24}
          md={24}
          sm={24}
          xs={24}
          style={{
            marginBottom: 24,
          }}
        >
          <Card
            title={"矿工总体信息"}
            bordered={false}
          >
            <div className="site-statistic-demo-card">
              <Row gutter={[16, 16]}>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="矿工总余额"
                      value={data.TotalBalance && data.TotalBalance.toFixed(2)}
                      valueStyle={{ color: '#3f8600' }}
                      suffix="FIL"
                      precision={2}
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="总有效算力"
                      value={data.QualityAdjPower && data.QualityAdjPower.toFixed(2)}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix="TiB"
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="算力占比"
                      value={data.PowerRatio && data.PowerRatio.toFixed(2)}
                      precision={2}
                      valueStyle={{ color: '#3f8600' }}
                      suffix="%"
                    />
                  </Card>
                </Col>
                <Col span={8}>
                  <Card>
                    <Statistic
                      title="总累计出块数"
                      value={data.RewardCount && data.RewardCount.toFixed(2)}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="总累计出块奖励"
                      value={data.RewardFil && data.RewardFil.toFixed(2)}
                      valueStyle={{ color: '#3f8600' }}
                      suffix="FIL"
                      precision={2}
                    />
                  </Card>
                </Col>

                <Col span={8}>
                  <Card>
                    <Statistic
                      title="高度"
                      value={data.Height}
                      valueStyle={{ color: '#3f8600' }}
                    />
                  </Card>
                </Col>
              </Row>
            </div>
          </Card>
        </Col>
      </Row>
      <ProTable
        actionRef={actionRef}
        rowKey="MinerId"
        search={false}
        options={false}
        // toolBarRender={false}
        columns={columns}
        dataSource={data.List}
      />
    </PageContainer>
  );
};
